package com.atguigu.consumer.sao.fallback;

import com.atguigu.consumer.sao.UserSao;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.cloud.openfeign.FallbackFactory;
import org.springframework.stereotype.Component;

/**
 * @author 郑启
 * @date 2021/09/27 15:50
 */
@Slf4j
@Component
public class UserFallbackFactory implements FallbackFactory<UserSao> {
	@Value("${spring.application.name}")
	private String appName;

	@Override
	public UserSao create(Throwable cause) {
		log.error("请求异常：" + cause.getMessage());
		return new UserSao() {
			@Override
			public String getProfile(String profile) {
				return appName + "-provider.user.getProfile 服务繁忙，请稍后再试";
			}

			@Override
			public String getTimeout() {
				return appName + "-provider.user.getTimeout 服务繁忙，请稍后再试";
			}

			@Override
			public String getDivide(int divisor) {
				return appName + "-provider.user.getDivide(" + divisor + ") 服务繁忙，请稍后再试";
			}

			@Override
			public String getConfigInfo() {
				return appName + "-provider.user.getConfigInfo 服务繁忙，请稍后再试";
			}
		};
	}
}
